import Vue from "vue";

let child = null;
Vue.mixin({

    methods: {
        hasAuth(perm) {
            let authorities = this.$store.state.menus.permList;

            return authorities.indexOf(perm) > -1;
        },
        getPagePerms(name) {

            getPagePermsByList(name, this.$store.state.menus.navList);
            let pagePerms = [];
            if (child) {
                child.forEach(menus => {
                    if (this.hasAuth(menus.name)) {
                        pagePerms.push({
                            perms: menus.name,
                            value: true
                        })
                    }
                })
            } else {
                console.log("权限为空")
            }

            return pagePerms;
        }

    }
})

function getPagePermsByList(name, menuList) {
    menuList.forEach(menu => {
        if (menu.type === 0 && menu.children) {
            getPagePermsByList(name, menu.children);
        } else if (menu.type === 1 && menu.name === name) {
            child = menu.children;
        }
    })
}
